<?php

namespace app\model;

use support\Model;
use support\Request;
class AdminLogModel extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'admin_log';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * 可批量赋值的属性
     *
     * @var array
     */
    protected $fillable = [
        'admin_id',      // 管理员ID
        'action',        // 操作类型(格式:module.action)
        'content',       // 操作内容
        'created_at',    // 创建时间
        'ip'             // IP地址
    ];

    /**
     * 记录管理员操作日志
     *
     * @param int $adminId 管理员ID
     * @param string $action 操作类型
     * @param string $content 操作内容
     * @return bool
     */
    public static function record(int $adminId, string $action, string $content = '',$ip = null): bool
    {
        $log = new self();
        $log->admin_id = $adminId;
        $log->action = $action;
        $log->content = $content;
        $log->created_at = time();
        $log->ip = $ip;
        return $log->save();
    }

    public function admin()
    {
        return $this->belongsTo(AdminModel::class, 'admin_id', 'id');
    }
} 